package com.junxian.springboot03.common;

import redis.clients.jedis.Jedis;

public class TestList {

    public static void main(String[] args) {
        Jedis jedis = new Jedis("192.168.31.90", 6379);
        jedis.auth("123456");

        jedis.flushDB();
        System.out.println("==========添加第一个list（左侧添加）==========");
        jedis.lpush("leftCollections", "ArrayList", "Vector", "Stack", "HashMap", "LinkHashMap");
        jedis.lpush("leftCollections", "TreeMap");
        jedis.lpush("leftCollections", "HashSet");
        jedis.lpush("leftCollections", "TreeMap");
        jedis.lpush("leftCollections", "TreeSet");
        jedis.lpush("leftCollections", "TreeMap");
        System.out.println("leftCollections的内容："+jedis.lrange("leftCollections", 0, -1));
        System.out.println("leftCollections的内容0-3的元素："+jedis.lrange("leftCollections", 0, 3));

        System.out.println("==========添加第二个list（右侧添加）==========");
        jedis.rpush("rightCollections", "ArrayList", "Vector", "Stack", "HashMap", "LinkHashMap");
        jedis.rpush("rightCollections", "HashSet");
        jedis.rpush("rightCollections", "TreeSet");
        jedis.rpush("rightCollections", "TreeMap");
        jedis.rpush("rightCollections", "TreeMap");
        System.out.println("rightCollections的内容："+jedis.lrange("rightCollections", 0, -1));
        System.out.println("rightCollections的内容0-3的元素："+jedis.lrange("rightCollections", 0, 3));

        System.out.println("==============================");
        //删除列表指定的值，第一个值是key，第二个参数是删除的个数（有重复时），后add进去的值先被删除
        System.out.println("删除leftCollections指定元素："+jedis.lrem("leftCollections", 2, "TreeMap"));
        System.out.println("leftCollections的内容："+jedis.lrange("leftCollections", 0, -1));
        System.out.println("删除leftCollections指定0-3区间之外的元素："+jedis.ltrim("leftCollections", 0, 3));
        System.out.println("leftCollections的内容："+jedis.lrange("leftCollections", 0, -1));
        System.out.println("leftCollections的内容出栈（左端）："+jedis.lpop("leftCollections"));
        System.out.println("leftCollections的内容："+jedis.lrange("leftCollections", 0, -1));
        System.out.println("leftCollections添加内容，从列表右端，与lpush相对："+jedis.rpush("leftCollections", "EnumMap"));
        System.out.println("leftCollections的内容："+jedis.lrange("leftCollections", 0, -1));
        System.out.println("leftCollections的内容出栈（右端）："+jedis.rpop("leftCollections"));
        System.out.println("leftCollections的内容："+jedis.lrange("leftCollections", 0, -1));
        System.out.println("修改leftCollections指定下标1的内容："+jedis.lset("leftCollections", 1, "lSetValue"));
        System.out.println("leftCollections的内容："+jedis.lrange("leftCollections", 0, -1));

        System.out.println("==============================");
        System.out.println("leftCollections的内容长度："+jedis.llen("leftCollections"));
        System.out.println("获取leftCollections指定下标为2的内容："+jedis.lindex("leftCollections", 2));
        jedis.lpush("sortedList", "3","1","4","0","35","23","5","23","2","9");
        System.out.println("获取sortedList排序前的内容："+jedis.lrange("sortedList", 0, -1));
        System.out.println("获取sortedList排序后的内容："+jedis.sort("sortedList"));
    }
}
